package com.example.rxtxdemo.rxtx;


import cn.hutool.core.util.HexUtil;
import com.google.common.collect.Maps;
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.SerialPort;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor
public class RxtxNewRest {



//    @GetMapping("ports")
//    public Map<String, Object> test() {
//        Map<String, Object> map = Maps.newHashMap();
//        List<String> ports = RxtxSerialPortManager.findPorts();
////        ports.forEach(port -> map.put(port, SerialPort.getCommPort(port).isOpen()));
//        return map;
//    }




    @GetMapping("statusRxtx")
    public Boolean statusRxtx(@RequestParam String portName) throws NoSuchPortException {
        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);


        return portIdentifier.isCurrentlyOwned();
    }
    public static void main(String[] args) {
        System.out.println(HexUtil.toHex(70));
    }

}
